'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	//连接云数据库
	const db = uniCloud.database();
	var username = event.username
	var password = event.password
	//查找数据库表
	let result = await db.collection('users').where({
		username:username
	}).get();
	console.log(result)
	if (result.affectedDocs == 0) {
		return {
			code: 500,
			msg: "用户不存在"
		}
	} else {
		if (password == result.data[0].password) {
			return {
				code: 200,
				msg: "登录成功",
				msg: result.data[0]
			}
		} else {
			return {
				code: 500,
				msg: "密码错误"
			}
		}
	}
	//返回数据给客户端
	return event
};